﻿using System;
using System.Windows.Forms;
using Relocation.Data;
using Relocation.Base;
using Relocation.Com;
using Relocation.Forms.ListBase;

namespace Relocation
{
	public partial class projectSelect : ProjectListBase
	{
		public Projects Project
		{
			get;
			private set;
		}

		public projectSelect():base()
		{
			Initialize();
		}

		public projectSelect(Session session):base(session)
		{
			Initialize();
		}

		public void Initialize()
		{
			InitializeComponent();
			this.ObjectQuery = this.Session.DataModel.Projects;
		}

		//flag为true，第一次必须选择项目
		public projectSelect(Session session, Boolean flag):this(session)
		{
			cancelBT.Enabled = !flag;
		}

		//确定
		private void okBT_Click(object sender, EventArgs e)
		{
			try
			{
				this.Project = this.GetSelectEntity();
				this.DialogResult = DialogResult.OK;
				this.Close();
			} catch (Exception ex)
			{
				Log.Error(ex.Message);
				MyMessagebox.Error(ex.Message);
			}
		}

		//取消
		private void cancelBT_Click(object sender, EventArgs e)
		{
			this.Close();
		}
	}
}
